package com.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.TreeMap;


/**
 * @author liaogui
 * @date 2024/8/6 11:46
 * @Description:
 */
public class JSONSort {
    public static String sortJSONObject(JSONObject jsonObject) {
        TreeMap<String, Object> treeMap = new TreeMap<>();

        // 将JSONObject中的键值对添加到TreeMap中
        for (String key : jsonObject.keySet()) {
            treeMap.put(key, jsonObject.get(key));
        }

        return JSON.toJSONString(treeMap);
    }

}
